package hsh.gui;

import javax.swing.*;

import org.omg.CORBA.INITIALIZE;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class SystemTimeLabel extends JLabel implements ActionListener {

	private javax.swing.Timer timer;

	private GregorianCalendar calendar;

	private Date data;

	public SystemTimeLabel() {

		super();

		initialize();

		disparaRelogio();
	}

	private void initialize() {
		this.calendar = new GregorianCalendar(2009, 1, 1, 0, 0);

		this.setIcon(new ImageIcon("resources/icons/clock_icon.png"));
		// this.setFont(new Font("Arial", Font.BOLD, 22));
	}

	public void disparaRelogio() {
		if (timer == null) {
			timer = new javax.swing.Timer(1000, this);
			timer.setInitialDelay(0);
			timer.start();
		} else if (!timer.isRunning()) {
			timer.restart();
		}
	}

	public void actionPerformed(ActionEvent ae) {
		// GregorianCalendar calendario = new GregorianCalendar();
		// GregorianCalendar calendario = new GregorianCalendar(2009,1,1,0,0);
		calendar.add(GregorianCalendar.SECOND, 1);

		// int h = calendar.get(GregorianCalendar.HOUR_OF_DAY);
		int m = calendar.get(GregorianCalendar.MINUTE);
		int s = calendar.get(GregorianCalendar.SECOND);

		String hora = /* ((h < 10) ? "0" : "") + h + ":" + */((m < 10) ? "0"
				: "")
				+ m + ":" + ((s < 10) ? "0" : "") + s;

		this.setText("System Time: " + hora);
	}
}